/*
 * Copyright 2020-2021 the original author or authors.
 *
 * Licensed under the General Public License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.gnu.org/licenses/gpl-3.0.en.html
 */

package team.seekers.oj.problem.controller;

import org.springframework.beans.BeanUtils;
import team.seekers.oj.common.exception.InternalApiException;
import team.seekers.oj.problem.api.ProblemApi;
import team.seekers.oj.problem.dao.ProblemDao;
import team.seekers.oj.problem.dto.ProblemDTO;
import team.seekers.oj.problem.dto.ProblemForCodeTestDTO;
import team.seekers.oj.problem.dto.ProblemJudgerDTO;
import team.seekers.oj.problem.dto.ProblemListDTO;
import team.seekers.oj.problem.entity.ProblemDO;
import team.seekers.oj.problem.service.ProblemJudgerService;
import team.seekers.oj.problem.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ProblemInternalController
 * @Description TODO
 * @Author zhangt2333
 * @Date 2020/4/9 15:46
 * @Version V1.0
 **/

@RestController
public class ProblemInternalController implements ProblemApi {
    
    
    @Autowired
    private ProblemDao problemDao;

    @Autowired
    private ProblemService problemService;

    @Autowired
    private ProblemJudgerService problemJudgerService;

    @Override
    public String problemIdToProblemTitle(long problemId) {
        return problemService.problemIdToProblemTitle(problemId);
    }

    @Override
    public int problemIdToProblemCheckpointNum(long problemId) {
        return problemService.problemIdToProblemCheckpointNum(problemId);
    }

    @Override
    public String problemIdToProblemCode(long problemId) {
        return problemService.problemIdToProblemCode(problemId);
    }

    @Override
    public Long problemCodeToProblemId(String problemCode) {
        return problemService.problemCodeToProblemId(problemCode);
    }



//    @Override
//    public List<String> problemIdToProblemCodeList(ArrayList<Long> problemIds) {
//        return problemService.problemIdToProblemCodeList(problemIds);
//    }

    @Override
    public Map<Long, String> queryIdToTitleMap() throws InternalApiException {
        return problemService.queryIdToTitleMap();
    }

    @Override
    public boolean validateProblemCodeList(List<String> problemCodeList) throws InternalApiException {
        return problemService.validateProblemCodeList(problemCodeList);
    }

    @Override
    public ProblemDTO queryProblemWithDescriptionId(String problemCode, long problemDescriptionId) {
        return problemService.queryWithDescriptionId(problemCode, problemDescriptionId);
    }

    @Override
    public List<Long> queryPrivateProblemIdList(Long exclusiveUserId) {
        return problemService.queryPrivateProblemIdList(exclusiveUserId);
    }

    @Override
    public ProblemJudgerDTO queryProblemJudgeDTO(Long problemId) {
        return problemJudgerService.queryById(problemId);
    }

    @Override
    public List<ProblemForCodeTestDTO> queryProblemsByIds(List<Long> problemIds) {

//        List<ProblemForCodeTestDTO> problemForCodeTestDTOS = new ArrayList<>();
//        for(Long problemId : problemIds){
//            ProblemForCodeTestDTO problemForCodeTestDTO = new ProblemForCodeTestDTO();
//            ProblemDO problemDO = problemDao.getById(problemId);
//            problemForCodeTestDTO.setProblemId(problemDO.getProblemId());
//            problemForCodeTestDTO.setProblemTitle(problemDO.getProblemTitle());
//            problemForCodeTestDTO.setAcceptNum(problemDO.getAcceptNum());
//            problemForCodeTestDTO.setSubmitNum(problemDO.getSubmitNum());
//            problemForCodeTestDTO.setProblemCode(problemDO.getProblemCode());
//            problemForCodeTestDTO.setSource(problemDO.getSource());
//            problemForCodeTestDTOS.add(problemForCodeTestDTO);
//        }
        return problemService.queryProblemsByIds(problemIds);
    }

    @Override
    public ProblemDTO queryProblemsById(Long problemId) {
        ProblemDO problemDO = problemDao.getById(problemId);
        ProblemDTO problemDTO = new ProblemDTO();
        BeanUtils.copyProperties(problemDO,problemDTO);
        return problemDTO;
    }


}
